package com.egov.business.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.egov.business.system.entity.SysUser;
import com.egov.business.system.mapper.SysUserMapper;
import com.egov.business.system.mapper.SysUserRoleMapper;
import com.egov.business.system.model.SysUserCacheInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户表 服务实现类
 *
 * @author denggang
 * @Date 2019-05-13
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> {

	@Autowired
	private SysUserMapper userMapper;

	@Autowired
	private SysUserRoleMapper sysUserRoleMapper;

	public SysUser getUserByName(String username) {
		return userMapper.getUserByName(username);
	}

	public List<String> getRole(String username) {
		return sysUserRoleMapper.getRoleByUserName(username);
	}

	public SysUserCacheInfo getCacheUser(String username) {
		SysUserCacheInfo info = new SysUserCacheInfo();
		info.setOneDepart(true);
		SysUser user = userMapper.getUserByName(username);
		info.setSysUserCode(user.getUsername());
		info.setSysUserName(user.getRealname());

//		List<SysDepart> list = sysDepartMapper.queryUserDeparts(user.getId());
//		List<String> sysOrgCode = new ArrayList<String>();
//		if(list==null || list.size()==0) {
//			//当前用户无部门
//			sysOrgCode.add("0");
//		}else if(list.size()==1) {
//			sysOrgCode.add(list.get(0).getOrgCode());
//		}else {
//			info.setOneDepart(false);
//			for (SysDepart dpt : list) {
//				sysOrgCode.add(dpt.getOrgCode());
//			}
//		}
//		info.setSysOrgCode(sysOrgCode);
		// TODO companycode 没有处理
		return info;
	}

}
